package cn.com.twoke.easyproject;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.ComponentScans;
import org.springframework.core.env.Environment;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Objects;

@Slf4j
@SpringBootApplication
@EnableTransactionManagement
@MapperScan("cn.com.twoke.easyproject.**.mapper")
public class EasyProjectApplication {

    public static void main(String[] args){
        ConfigurableApplicationContext application = SpringApplication.run(EasyProjectApplication.class, args);
        Environment env = application.getEnvironment();


        String port = env.getProperty("server.port");
        String contextPath = env.getProperty("server.servlet.context-path");
        StringBuilder sb = new StringBuilder();
        sb.append("\n----------------------------------------------------------\n\t");
        sb.append(String.format("Application '%s' is running! Access URLs:\n\t", env.getProperty("spring.application.name")));
        String address = String.format("http://localhost:%s", env.getProperty("server.port"), port);
        if (Objects.nonNull(contextPath)) {
            address += contextPath;
        }
        sb.append(String.format("Local: \t\t%s\n\t", address));
        try {
            address = String.format("http://%s:%s", InetAddress.getLocalHost().getHostAddress(), port);
            if (Objects.nonNull(contextPath)) {
                address += contextPath;
            }
            sb.append(String.format("External: \t%s\n\t", address));
        } catch (UnknownHostException e) {}
        sb.append(String.format("Doc: \t\t%s/doc.html\n", address));
        sb.append("----------------------------------------------------------\n");
        log.info(sb.toString());
    }


}